/******************************************************************************
* file  : console.c
* creat : apleilx
* data  : 2021/01/20
*******************************************************************************/
#include "os_obj.h"
#include "sys_task.h"
#include "pincfg.h"
#include "com_obj.h"
#include "dataproc.h"
#include "common.h"
#include "str_ext.h"

static uint8_t console_buff[1024];
void cmd_analysis(uint8_t *cmd);
void sys_ui_tst(void);

/*****************************************************************************
* @brief   console task.
* @param   argument
* @return  none
*****************************************************************************/
void task_console(void * thread_input)
{
  uint16_t len;

  while (1)
  {
    osDelay(ms_ticks(20));

    len = com.obj01.fun->cycle_rcv_line(console_buff);

    if (len > 0)
    {
      str_to_upper(console_buff);
      str_remove_l20_ascii(console_buff);

      cmd_analysis(console_buff);
    }
  }
}

/*****************************************************************************
* @brief   cmd analysis.
* @param   cmd: cmd string
* @return  none
*****************************************************************************/
void cmd_analysis(uint8_t *cmd)
{
  int index;

  if (0 == comp_string(cmd, (uu8*)"RST", 1024))
  {
    dbg_puts("cmd rst\n");
    osDelay(ms_ticks(100));
    NVIC_SystemReset();
  }
  else if (0 == comp_string(cmd, (uu8*)"TIME", 1024))
  {
    dbg_print("time run: %08dms\n", sys_st.u_tick);
  }
  else if (0 == comp_string(cmd, (uu8*)"COREMARK", 1024))
  {
    sys_st.b_coremark = 1;
  }
  else if (0 == comp_string(cmd, (uu8*)"LX-CLR", 1024))
  {
    sys_st.lx_clr_req = 1;
  }
  else if (0 == comp_string(cmd, (uu8*)"LX-TST", 1024))
  {
    sys_st.lx_tst_req = 1;
  }
  else
  {

  }
}


